
Imports System.Windows.Forms

Public Class setControlEnabled

    Private ctrls() As Control


    Public Sub New(ByRef ctrl() As Control)
        Me.ctrls = ctrl
    End Sub


    Public Sub SetControlsEnabled(ByVal bEnabled As Boolean)

        Dim bReadOnly As Boolean = Not (bEnabled)

        For Each p As Control In ctrls

            For Each ctrl As Control In p.Controls
                If TypeOf ctrl Is TextBox Then
                    DirectCast(ctrl, TextBox).ReadOnly = bReadOnly
                ElseIf TypeOf ctrl Is ComboBox Then
                    DirectCast(ctrl, ComboBox).Enabled = bEnabled
                ElseIf TypeOf ctrl Is DateTimePicker Then
                    DirectCast(ctrl, DateTimePicker).Enabled = bEnabled
                ElseIf TypeOf ctrl Is RichTextBox Then
                    DirectCast(ctrl, RichTextBox).ReadOnly = bReadOnly
                End If
            Next

        Next

    End Sub

End Class
